<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>新增检测项</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="cancel">返回</el-button>
      </div>

      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="检测项名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入检测项名称" />
        </el-form-item>

        <el-form-item label="检测类型" prop="itemType">
          <el-select v-model="form.itemType" placeholder="请选择检测类型">
            <el-option
              v-for="item in itemTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="检测标准" prop="standard">
          <el-input v-model="form.standard" type="textarea" rows="3" placeholder="请输入检测标准" />
        </el-form-item>

        <el-form-item label="检测方法" prop="method">
          <el-input v-model="form.method" type="textarea" rows="3" placeholder="请输入检测方法" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'AddDetectionItemSettings',
  data() {
    return {
      // 表单参数
      form: {
        itemName: '',
        itemType: '',
        standard: '',
        method: ''
      },
      // 检测类型选项
      itemTypeOptions: [
        { value: '1', label: '尺寸检测' },
        { value: '2', label: '外观检测' },
        { value: '3', label: '功能检测' },
        { value: '4', label: '性能检测' }
      ],
      // 表单校验
      rules: {
        itemName: [
          { required: true, message: '检测项名称不能为空', trigger: 'blur' }
        ],
        itemType: [
          { required: true, message: '请选择检测类型', trigger: 'change' }
        ],
        standard: [
          { required: true, message: '检测标准不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 实际应调用后端API
          this.$modal.msgSuccess("新增成功");
          this.cancel();
        }
      });
    },
    /** 取消按钮 */
    cancel() {
      this.$router.push({ path: "/sb/DetectionItemSettings" });
    }
  }
}
</script> 